|
1
|
|
|
/* |
|
2
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
3
|
|
|
* To change this template file, choose Tools | Templates |
|
4
|
|
|
* and open the template in the editor. |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/* global API */ |
|
9
|
|
|
|
|
10
|
|
|
API.tabs = { |
|
11
|
|
|
connect: function(tabId, connectInfo) { |
|
12
|
|
|
return API.api.tabs.connect(tabId, connectInfo); |
|
13
|
|
|
}, |
|
14
|
|
|
create: function(parameters) { |
|
15
|
|
|
if (API.promise) { |
|
16
|
|
|
return API.api.tabs.create(parameters); |
|
17
|
|
|
} |
|
18
|
|
|
else { |
|
19
|
|
|
return new C_Promise(function() { |
|
20
|
|
|
API.api.tabs.create(parameters, (function (tab) { |
|
21
|
|
|
this.call_then(tab); |
|
22
|
|
|
}).bind(this)); |
|
23
|
|
|
}); |
|
24
|
|
|
} |
|
25
|
|
|
}, |
|
26
|
|
|
captureVisibleTab: function(windowId, options) { |
|
27
|
|
|
if (API.promise) { |
|
28
|
|
|
return API.api.tabs.captureVisibleTab(windowId, options); |
|
29
|
|
|
} |
|
30
|
|
|
else { |
|
31
|
|
|
return new C_Promise(function() { |
|
32
|
|
|
API.api.tabs.captureVisibleTab(windowId, options, (function(dataUrl) { |
|
33
|
|
|
this.call_then(dataUrl); |
|
34
|
|
|
}).bind(this)); |
|
35
|
|
|
}); |
|
36
|
|
|
} |
|
37
|
|
|
}, |
|
38
|
|
|
detectLanguage: function(tabId) { |
|
39
|
|
|
if (API.promise) { |
|
40
|
|
|
return API.api.tabs.detectLanguage(tabId); |
|
41
|
|
|
} |
|
42
|
|
|
else { |
|
43
|
|
|
return new C_Promise(function() { |
|
44
|
|
|
API.api.tabs.detectLanguage(tabId, (function(language) { |
|
45
|
|
|
this.call_then(language); |
|
46
|
|
|
}).bind(this)); |
|
47
|
|
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
}, |
|
50
|
|
|
duplicate: function(tabId) { |
|
51
|
|
|
if (API.promise) { |
|
52
|
|
|
return API.api.tabs.duplicate(tabId); |
|
53
|
|
|
} |
|
54
|
|
|
else { |
|
55
|
|
|
return new C_Promise(function() { |
|
56
|
|
|
API.api.tabs.duplicate(tabId, (function(tab) { |
|
57
|
|
|
this.call_then(tab); |
|
58
|
|
|
}).bind(this)); |
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
61
|
|
|
}, |
|
62
|
|
|
executeScript: function(tabId, details) { |
|
63
|
|
|
if (API.promise) { |
|
64
|
|
|
return API.api.tabs.executeScript(tabId, details); |
|
65
|
|
|
} |
|
66
|
|
|
else { |
|
67
|
|
|
return new C_Promise(function() { |
|
68
|
|
|
API.api.tabs.executeScript(tabId, details, (function(result) { |
|
69
|
|
|
this.call_then(result); |
|
70
|
|
|
}).bind(this)); |
|
71
|
|
|
}); |
|
72
|
|
|
} |
|
73
|
|
|
}, |
|
74
|
|
|
get: function(tabId) { |
|
75
|
|
|
if (API.promise) { |
|
76
|
|
|
return API.api.tabs.get(tabId); |
|
77
|
|
|
} |
|
78
|
|
|
else { |
|
79
|
|
|
return new C_Promise(function() { |
|
80
|
|
|
API.api.tabs.get(tabId, (function(tab) { |
|
81
|
|
|
this.call_then(tab); |
|
82
|
|
|
}).bind(this)); |
|
83
|
|
|
}); |
|
84
|
|
|
} |
|
85
|
|
|
}, |
|
86
|
|
|
getCurrent: function() { |
|
87
|
|
|
if (API.promise) { |
|
88
|
|
|
return API.api.tabs.getCurrent(); |
|
89
|
|
|
} |
|
90
|
|
|
else { |
|
91
|
|
|
return new C_Promise(function() { |
|
92
|
|
|
API.api.tabs.getCurrent((function(tab) { |
|
93
|
|
|
this.call_then(tab); |
|
94
|
|
|
}).bind(this)); |
|
95
|
|
|
}); |
|
96
|
|
|
} |
|
97
|
|
|
}, |
|
98
|
|
|
getZoom: function(tabId) { |
|
99
|
|
|
if (API.promise) { |
|
100
|
|
|
return API.api.tabs.getZoom(tabId); |
|
101
|
|
|
} |
|
102
|
|
|
else { |
|
103
|
|
|
return new C_Promise(function() { |
|
104
|
|
|
API.api.tabs.getZoom(tabId, (function(zoom) { |
|
105
|
|
|
this.call_then(zoom); |
|
106
|
|
|
}).bind(this)); |
|
107
|
|
|
}); |
|
108
|
|
|
} |
|
109
|
|
|
}, |
|
110
|
|
|
getZoomSettings: function(tabId) { |
|
111
|
|
|
if (API.promise) { |
|
112
|
|
|
return API.api.tabs.getZoomSettings(tabId); |
|
113
|
|
|
} |
|
114
|
|
|
else { |
|
115
|
|
|
return new C_Promise(function() { |
|
116
|
|
|
API.api.tabs.getZoomSettings(tabId, (function(setting) { |
|
117
|
|
|
this.call_then(setting); |
|
118
|
|
|
}).bind(this)); |
|
119
|
|
|
}); |
|
120
|
|
|
} |
|
121
|
|
|
}, |
|
122
|
|
|
highlight: function(highlightInfo) { |
|
123
|
|
|
if (API.promise) { |
|
124
|
|
|
return new C_Promise(function() { |
|
125
|
|
|
this.call_then(); // Firefox seems to not support this |
|
126
|
|
|
}); |
|
127
|
|
|
} |
|
128
|
|
|
else { |
|
129
|
|
|
return new C_Promise(function() { |
|
130
|
|
|
API.api.tabs.highlight(highlightInfo, (function(window) { |
|
131
|
|
|
this.call_then(window); |
|
132
|
|
|
}).bind(this)); |
|
133
|
|
|
}); |
|
134
|
|
|
} |
|
135
|
|
|
}, |
|
136
|
|
|
insertCSS: function(tabId, details) { |
|
137
|
|
|
if (API.promise) { |
|
138
|
|
|
return API.api.tabs.insertCSS(tabId, details); |
|
139
|
|
|
} |
|
140
|
|
|
else { |
|
141
|
|
|
return new C_Promise(function() { |
|
142
|
|
|
API.api.tabs.insertCSS(tabId, details, (function() { |
|
143
|
|
|
this.call_then(); |
|
144
|
|
|
}).bind(this)); |
|
145
|
|
|
}); |
|
146
|
|
|
} |
|
147
|
|
|
}, |
|
148
|
|
|
removeCSS: function(tabId, details) { |
|
149
|
|
|
if (API.promise) { |
|
150
|
|
|
return API.api.tabs.removeCSS(tabId, details); |
|
151
|
|
|
} |
|
152
|
|
|
else { |
|
153
|
|
|
return new C_Promise(function() { |
|
154
|
|
|
this.call_then(); // Not supported by chrome |
|
155
|
|
|
}); |
|
156
|
|
|
} |
|
157
|
|
|
}, |
|
158
|
|
|
move: function(tabIds, moveProperties) { |
|
159
|
|
|
if (API.promise) { |
|
160
|
|
|
return API.api.tabs.move(tabIds, moveProperties); |
|
161
|
|
|
} |
|
162
|
|
|
else { |
|
163
|
|
|
return new C_Promise(function() { |
|
164
|
|
|
API.api.tabs.move(tabIds, moveProperties, (function(tabs) { |
|
165
|
|
|
this.call_then(tabs); |
|
166
|
|
|
}).bind(this)); |
|
167
|
|
|
}); |
|
168
|
|
|
} |
|
169
|
|
|
}, |
|
170
|
|
|
query: function(queryInfo) { |
|
171
|
|
|
if (API.promise) { |
|
172
|
|
|
return API.api.tabs.query(queryInfo); |
|
173
|
|
|
} |
|
174
|
|
|
else { |
|
175
|
|
|
return new C_Promise(function() { |
|
176
|
|
|
API.api.tabs.query(queryInfo, (function(tabs) { |
|
177
|
|
|
this.call_then(tabs); |
|
178
|
|
|
}).bind(this)); |
|
179
|
|
|
}); |
|
180
|
|
|
} |
|
181
|
|
|
}, |
|
182
|
|
|
reload: function(tabId, reloadProperties) { |
|
183
|
|
|
if (API.promise) { |
|
184
|
|
|
return API.api.tabs.reload(tabId, reloadProperties); |
|
185
|
|
|
} |
|
186
|
|
|
else { |
|
187
|
|
|
return new C_Promise(function() { |
|
188
|
|
|
API.api.tabs.reload(tabId, reloadProperties, (function() { |
|
189
|
|
|
this.call_then(); |
|
190
|
|
|
}).bind(this)); |
|
191
|
|
|
}); |
|
192
|
|
|
} |
|
193
|
|
|
}, |
|
194
|
|
|
remove: function(tabIds) { |
|
195
|
|
|
if (API.promise) { |
|
196
|
|
|
return API.api.tabs.remove(tabIds); |
|
197
|
|
|
} |
|
198
|
|
|
else { |
|
199
|
|
|
return new C_Promise(function() { |
|
200
|
|
|
API.api.tabs.remove(tabIds, (function() { |
|
201
|
|
|
this.call_then(); |
|
202
|
|
|
}).bind(this)); |
|
203
|
|
|
}); |
|
204
|
|
|
} |
|
205
|
|
|
}, |
|
206
|
|
|
sendMessage: function(tabId, message, options) { |
|
207
|
|
|
if (API.promise) { |
|
208
|
|
|
return API.api.tabs.sendMessage(tabId, message, options); |
|
209
|
|
|
} |
|
210
|
|
|
else { |
|
211
|
|
|
return new C_Promise(function() { |
|
212
|
|
|
API.api.tabs.sendMessage(tabId, message, options, (function(response) { |
|
213
|
|
|
this.call_then(response); |
|
214
|
|
|
}).bind(this)); |
|
215
|
|
|
}); |
|
216
|
|
|
} |
|
217
|
|
|
}, |
|
218
|
|
|
setZoom: function(tabId, zoomFactor) { |
|
219
|
|
|
if (API.promise) { |
|
220
|
|
|
return API.api.tabs.setZoom(tabId, zoomFactor); |
|
221
|
|
|
} |
|
222
|
|
|
else { |
|
223
|
|
|
return new C_Promise(function() { |
|
224
|
|
|
API.api.tabs.setZoom(tabId, zoomFactor, (function() { |
|
225
|
|
|
this.call_then(); |
|
226
|
|
|
}).bind(this)); |
|
227
|
|
|
}); |
|
228
|
|
|
} |
|
229
|
|
|
}, |
|
230
|
|
|
update: function(tabId, updateProperties) { |
|
231
|
|
|
if (API.promise) { |
|
232
|
|
|
return API.api.tabs.update(tabId, updateProperties); |
|
233
|
|
|
} |
|
234
|
|
|
else { |
|
235
|
|
|
return new C_Promise(function() { |
|
236
|
|
|
API.api.tabs.update(tabId, updateProperties, (function(tab) { |
|
237
|
|
|
this.call_then(tab); |
|
238
|
|
|
}).bind(this)); |
|
239
|
|
|
}); |
|
240
|
|
|
} |
|
241
|
|
|
}, |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Events from now on |
|
248
|
|
|
*/ |
|
249
|
|
|
onActivated: API.api.tabs.onActivated, |
|
250
|
|
|
onAttached: API.api.tabs.onAttached, |
|
251
|
|
|
onCreated: API.api.tabs.onCreated, |
|
252
|
|
|
onDetached: API.api.tabs.onDetached, |
|
253
|
|
|
onHighlighted: API.api.tabs.onHighlighted, |
|
254
|
|
|
onMoved: API.api.tabs.onMoved, |
|
255
|
|
|
onRemoved: API.api.tabs.onRemoved, |
|
256
|
|
|
onReplaced: API.api.tabs.onReplaced, |
|
257
|
|
|
onUpdated: API.api.tabs.onUpdated, |
|
258
|
|
|
onZoomChange: API.api.tabs.onZoomChange |
|
259
|
|
|
}; |